package com.hohai.mall.common.framework.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 校验工具类
 */
public class ValidationUtil {

    public static final Pattern phoneNumberPattern = Pattern.compile("^((13[0-9])|145|147|(15[^4,\\D])|(18[0-9])|(17[0-9]))\\d{8}$");

    public static final Pattern emailAddressPattern = Pattern.compile("^([a-z0-9A-Z]+[-\\._]*)+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");

    public static final Pattern IpPattern = Pattern.compile("([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}");

    public static final String percentFormatWithTwoDecimal = "##.##";

    public static boolean isMobile(String mobile) {
        Matcher matcher = phoneNumberPattern.matcher(mobile);
        if (matcher.find()) {
            return true;
        }
        return false;
    }

    public static boolean isEmailAddress(String emailAddress) {
        Matcher matcher = emailAddressPattern.matcher(emailAddress);
        if (matcher.find()) {
            return true;
        }
        return false;
    }

    public static boolean isIp(String ip) {
        Matcher matcher = IpPattern.matcher(ip);
        if (matcher.find()) {
            return true;
        }
        return false;
    }


}